import pyautogui as pyg
import pygetwindow as gw
import keyboard
import time 

# 调整窗口大小 800*600
# 窗口对齐左上角防止
# 装备防止第一格
# 其他装备先强化一次，加速增幅
# --------------------------
# 坐标不对，使用点击坐标获取工具自己调整 
# 自己安装依赖组件
# pip install pyautogui
# pip install keyboard
# 打包方法 pyinstaller.exe --onefile 自动增幅.py
pause=False 

DNF_WD = gw.getWindowsWithTitle("Dungeon & Fighter")[0]

#gw.activate()
#print(f"title:{DNF_WD}")
INIT_WIDTH=800
INIT_HEIGHT=600
def compute_position(x_offset,y_offset):
    y= DNF_WD.top+(INIT_HEIGHT/2+y_offset)*(DNF_WD.height/INIT_HEIGHT)
    x= DNF_WD.left+(INIT_WIDTH/2+x_offset)*(DNF_WD.width/INIT_WIDTH)
    return (x,y)
def get_position():
    try:
        # 获取当前鼠标的坐标
        x, y = pyg.position()
        print(f"Mouse position: X={x}, Y={y}")
        time.sleep(1)
    except KeyboardInterrupt:
        print("Program terminated.")

def click_dnf(x,y):
    pyg.moveTo(x,y,duration=0.3)
    pyg.mouseDown(button="left")
    pyg.mouseUp(button="left")

def pause():
    global pause 
    pause =  True
    print("暂停增福")
def start():
    global pause 
    pause =  False
    print("开始增福")
        
def zengfu():
    #增幅按钮位置
    (x,y)=compute_position(-110,55)
    click_dnf(x,y)
    #移动到装备第一格
    (x,y)=compute_position(85,-10)
    click_dnf(x,y)
    # 确认增幅
    (x,y)=compute_position(-30,85)
    click_dnf(x,y)
    # 保护卷确认
    (x,y)=compute_position(-30,50)
    click_dnf(x,y)
    time.sleep(1.5)
    #失败确认位置 410 350
    (x,y)=compute_position(0,30)
    click_dnf(x,y)
    # 失败确认位置2 406, Y=352
    (x,y)=compute_position(5,40)
    click_dnf(x,y)
    time.sleep(0.5)
keyboard.add_hotkey("ctrl+f9",start)
keyboard.add_hotkey("ctrl+f10",pause)
print("1,请按ctrl+f9开始 ，ctrl+f10停止增幅")
#print("1.调整窗口大小 800*600")
print("2.窗口对齐左上角放置")
print("3.装备防止第一格")
print("4.其他装备先强化一次，加速增幅")
print("5.打开增幅界面")
print("6.按ctrl+f9开始增幅")
print("7.按ctrl+f10停止增幅")
while True:
    if pause:
        time.sleep(1)
    else:
        # 增幅开关
        zengfu()
        # 获取坐标方法
        #get_position()

        
